/*=============================================================================
# FileName    :	enthernet_top.v
# Author      :	author
# Email       :	email@email.com
# Description :	本模块封装了arp，ping以及udp协议
                udp协议接收到的数据
                    如果是内部参数
# Version     :	1.0
# LastChange  :	2018-08-24 23:57:13
# ChangeLog   :	
=============================================================================*/

`timescale  1 ns/1 ps

module enthernet_top #
(
    parameter C_CLK_FREQ_HZ     = 125_000_000,
    parameter LOCAL_MAC_ADDR    = 48'hC400C4010102,
    parameter LOCAL_IP_ADDR     = {8'd192,8'd168,8'd1,8'd102},
    parameter LOCAL_UDP_PORT    = 16'd4444,
    parameter REMOTE_UDP_PORT   = 16'd6666
)
(
    input   wire                clk,            // 125M
    input   wire                clk_200m,
    input   wire                rst,

    output  wire [31:00]        load_parameter,
    output  wire [07:00]        load_m_axi_tdata,
    output  wire                load_m_axi_tvalid,
    input   wire                load_m_axi_tready,
    output  wire                load_m_axi_tlast,

    input   wire [31:00]        update_paramter,
    input   wire [07:00]        update_m_axi_tdata,
    input   wire                update_m_axi_tvalid,
    output  wire                update_m_axi_tready,
    input   wire                update_m_axi_tlast,
    /*port*/
    //--------------- MII Interface
    output  wire                phy_resetn,
    output  wire                gmii_tx_clk,
    output  wire [07:00]        gmii_txd,
    output  wire                gmii_tx_en,
    output  wire                gmii_tx_er,
    input   wire                gmii_rx_clk,
    input   wire [07:00]        gmii_rxd,
    input   wire                gmii_rx_dv,
    input   wire                gmii_rx_er      
);

wire    [47:00]             udp_m_axis_tsrcmac;
wire    [31:00]             udp_m_axis_tsrcip;
wire    [07:00]             udp_m_axis_tdata;
wire                        udp_m_axis_tvalid;
wire                        udp_m_axis_tlast;

wire    [47:00]             udp_s_axis_tdstmac;
wire    [31:00]             udp_s_axis_tdstip;
wire    [10:00]             udp_s_axis_tlen;
wire    [07:00]             udp_s_axis_tdata;
wire                        udp_s_axis_tvalid;
wire                        udp_s_axis_tready;
wire                        udp_s_axis_tlast;

(* KEEP = "TRUE" *)wire    [07:00]             tx_axis_fifo_tdata;
(* KEEP = "TRUE" *)wire                        tx_axis_fifo_tvalid;
(* KEEP = "TRUE" *)wire                        tx_axis_fifo_tlast;
(* KEEP = "TRUE" *)wire                        tx_axis_fifo_tready;

wire    [07:00]             rx_axis_fifo_tdata;
wire                        rx_axis_fifo_tvalid;
wire                        rx_axis_fifo_tlast;
wire                        rx_axis_fifo_tready;

//mac_core_example_design mac_core_example_designEx01
mac_core_user_top mac_core_user_topEx01
(
    .glbl_rst               (    rst                               ),
    .refclk_bufg            (    clk_200m                          ),
    .gtx_clk_bufg           (    clk                               ),

    .tx_fifo_clock          (    clk                               ),
    .tx_axis_fifo_tvalid    (    tx_axis_fifo_tvalid               ),
    .tx_axis_fifo_tdata     (    tx_axis_fifo_tdata                ),
    .tx_axis_fifo_tlast     (    tx_axis_fifo_tlast                ),
    .tx_axis_fifo_tready    (    tx_axis_fifo_tready               ),

    .rx_fifo_clock          (    clk                               ),
    .rx_axis_fifo_tdata     (    rx_axis_fifo_tdata                ),
    .rx_axis_fifo_tvalid    (    rx_axis_fifo_tvalid               ),
    .rx_axis_fifo_tlast     (    rx_axis_fifo_tlast                ),
    .rx_axis_fifo_tready    (    rx_axis_fifo_tready               ),


    .pause_req_s            (    0                                 ),
    .mac_speed              (    2'b10                             ),
    .update_speed           (    0                                 ),
    .config_board           (    0                                 ),
    //.serial_response      (    serial_response         ),
    .gen_tx_data            (    0                                 ),
    .chk_tx_data            (    0                                 ),
    .reset_error            (    0                                 ),
    //.frame_error          (    frame_error             ),
    //.frame_errorn         (    frame_errorn            ),
    //.activity_flash       (    activity_flash          ),
    //.activity_flashn      (    activity_flashn         )

    .phy_resetn             (    phy_resetn                        ),
    .gmii_txd               (    gmii_txd                          ),
    .gmii_tx_en             (    gmii_tx_en                        ),
    .gmii_tx_er             (    gmii_tx_er                        ),
    .gmii_tx_clk            (    gmii_tx_clk                       ),
    .gmii_rxd               (    gmii_rxd                          ),
    .gmii_rx_dv             (    gmii_rx_dv                        ),
    .gmii_rx_er             (    gmii_rx_er                        ),
    .gmii_rx_clk            (    gmii_rx_clk                       )
);

axi_udp_top #
(
    .C_CLK_FREQ_HZ          (    125_000_000                       ),
    .LOCAL_MAC_ADDR         (    48'hC400C4010102                  ),
    .LOCAL_IP_ADDR          (    {8'd192, 8'd168, 8'd1, 8'd102}    ),
    .LOCAL_UDP_PORT         (    16'd4444                          ),
    .REMOTE_UDP_PORT        (    16'd6666                          )
)
axi_udp_topEx01
(
    .rst                    (    rst                               ),
    .clk                    (    clk                               ),

    // udp数据字段接收接口
    .udp_m_axis_tsrcmac     (    udp_m_axis_tsrcmac                ),
    .udp_m_axis_tsrcip      (    udp_m_axis_tsrcip                 ),
    .udp_m_axis_tdata       (    udp_m_axis_tdata                  ),
    .udp_m_axis_tvalid      (    udp_m_axis_tvalid                 ),
    .udp_m_axis_tlast       (    udp_m_axis_tlast                  ),

    // udp数据字段发送接口
    .udp_s_axis_tdstmac     (    udp_s_axis_tdstmac                ),
    .udp_s_axis_tdstip      (    udp_s_axis_tdstip                 ),
    .udp_s_axis_tlen        (    udp_s_axis_tlen                   ),
    .udp_s_axis_tdata       (    udp_s_axis_tdata                  ),
    .udp_s_axis_tvalid      (    udp_s_axis_tvalid                 ),
    .udp_s_axis_tready      (    udp_s_axis_tready                 ),
    .udp_s_axis_tlast       (    udp_s_axis_tlast                  ),

    // MAC接收接口
    .mac_s_axis_tdata       (    rx_axis_fifo_tdata                ),
    .mac_s_axis_tvalid      (    rx_axis_fifo_tvalid               ),
    .mac_s_axis_tlast       (    rx_axis_fifo_tlast                ),
    .mac_s_axis_tready      (    rx_axis_fifo_tready               ),

    // MAC发送接口
    .mac_m_axis_tdata       (    tx_axis_fifo_tdata                ),
    .mac_m_axis_tvalid      (    tx_axis_fifo_tvalid               ),
    .mac_m_axis_tlast       (    tx_axis_fifo_tlast                ),
    .mac_m_axis_tready      (    tx_axis_fifo_tready               )
);

udp_user_top #
(
    .C_CLK_FREQ_HZ          (    125_000_000                       )
)
udp_user_topEx01
(
    .clk                    (    clk                               ),
    .rst                    (    rst                               ),

    .s_axis_tsrcmac         (    udp_m_axis_tsrcmac                ),
    .s_axis_tsrcip          (    udp_m_axis_tsrcip                 ),
    .s_axis_tdata           (    udp_m_axis_tdata                  ),
    .s_axis_tvalid          (    udp_m_axis_tvalid                 ),
    .s_axis_tlast           (    udp_m_axis_tlast                  ),

    .load_parameter         (    load_parameter                    ),
    .load_m_axi_tdata       (    load_m_axi_tdata                  ),
    .load_m_axi_tvalid      (    load_m_axi_tvalid                 ),
    .load_m_axi_tready      (    load_m_axi_tready                 ),
    .load_m_axi_tlast       (    load_m_axi_tlast                  ),

    .m_axis_tdstmac         (    udp_s_axis_tdstmac                ),
    .m_axis_tdstip          (    udp_s_axis_tdstip                 ),
    .m_axis_tlen            (    udp_s_axis_tlen                   ),
    .m_axis_tdata           (    udp_s_axis_tdata                  ),
    .m_axis_tvalid          (    udp_s_axis_tvalid                 ),
    .m_axis_tready          (    udp_s_axis_tready                 ),
    .m_axis_tlast           (    udp_s_axis_tlast                  ),

    .update_paramter        (    update_paramter                   ),
    .update_m_axi_tdata     (    update_m_axi_tdata                ),
    .update_m_axi_tvalid    (    update_m_axi_tvalid               ),
    .update_m_axi_tready    (    update_m_axi_tready               ),
    .update_m_axi_tlast     (    update_m_axi_tlast                )
);

endmodule
